package com.smartum.mpr.dao;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.smartum.mpr.model.County;
import com.smartum.mpr.model.State;

@Repository
public class StateDao extends GenericDao<Long, State> {

	@Override
	protected Class<State> getEntityClass() {
		return State.class;
	}

	public State getStateByName(String name) {
		DetachedCriteria criteria = DetachedCriteria.forClass(getEntityClass());
		criteria.add(Restrictions.eq("stateName", name));

		List<State> states = hibernateTemplate.findByCriteria(criteria, 0, 1);
		if (states.size() > 0) {
			return states.get(0);
		} else {
			return null;
		}
	}

	@Override
    public List<State> getList() {
		DetachedCriteria critteria = DetachedCriteria.forClass(State.class);
		critteria.addOrder(Order.asc("stateName"));
		return hibernateTemplate.findByCriteria(critteria);
    }
	
	
	
	

}
